﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    internal class RecordExamples
    {
        public static void Show()
        {
            //Person person = new Person("Nancy", "Davolio");
            //Console.WriteLine(person);

            // 下面的例子展示Record类型中的值相等性
            //var phoneNumbers = new string[2];
            //Person person1 = new Person("Nancy","Davolio",phoneNumbers);
            //Person person2 = new Person("Nancy", "Davolio", phoneNumbers);
            //Console.WriteLine(person1==person2);
            //person1.PhoneNumbers[0] = "555-1234";
            //Console.WriteLine(person1==person2);
            //Console.WriteLine(ReferenceEquals(person1,person2));

            // 下面的例子展示了使用 with表达式演示不可变对象和修改它的属性
            Person person1 = new Person("Nancy", "Davolio") { PhoneNumbers = new string[1] };
            Console.WriteLine(person1);
            Person person2 = person1 with { FirstName = "John" };
            Console.WriteLine(person2);
            Console.WriteLine(person1==person2);
            person2 = person1 with {PhoneNumbers = new string[1] };
            Console.WriteLine(person2);
            Console.WriteLine(person1==person2);
            person2 = person1 with { };
            Console.WriteLine(person1==person2);
        }
    }

    //public record Person(string FirstName,string LastName, string[] PhoneNumbers);

    public record Person(string FirstName,string LastName)
    {
        public required string[] PhoneNumbers { get; init; }
    }
}
